Name.getDate   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
var GedcomX = require('../'),
2
    utils = require('../utils');
3
4
/**
5
 * A name.
6
 * 
7
 * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#name-conclusion|GEDCOM X JSON Spec}
8
 * 
9
 * @class
10
 * @extends Conclusion
11
 * @param {Object} [json]
12
 */
13
var Name = function(json){
14
  
15
  // Protect against forgetting the new keyword when calling the constructor
16
  if(!(this instanceof Name)){
17
    return new Name(json);
18
  }
19
  
20
  // If the given object is already an instance then just return it. DON'T copy it.
21
  if(Name.isInstance(json)){
22
    return json;
23
  }
24
  
25
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
};
27
28
Name.prototype = Object.create(GedcomX.Conclusion.prototype);
29
30
Name._gedxClass = Name.prototype._gedxClass = 'GedcomX.Name';
31
32
Name.jsonProps = [
33
  'type',
34
  'date',
35
  'nameForms'
36
];
37
38
/**
39
 * Check whether the given object is an instance of this class.
40
 * 
41
 * @param {Object} obj
42
 * @returns {Boolean}
43
 */
44
Name.isInstance = function(obj){
45
  return utils.isInstance(obj, this._gedxClass);
46
};
47
48
/**
49
 * Initialize from JSON
50
 * 
51
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
52
 * @return {Name} this
53
 */
54
Name.prototype.init = function(json){
55
  
56
  GedcomX.Conclusion.prototype.init.call(this, json);
57
  
58
  if(json){
59
    this.setType(json.type);
60
    this.setDate(json.date);
61
    this.setNameForms(json.nameForms);
62
  }
63
  return this;
64
};
65
66
/**
67
 * Get the name type
68
 * 
69
 * @returns {String} type
70
 */
71
Name.prototype.getType = function(){
72
  return this.type;
73
};
74
75
/**
76
 * Set the name type
77
 * 
78
 * @param {String} type
79
 * @returns {Name} This instance
80
 */
81
Name.prototype.setType = function(type){
82
  this.type = type;
83
  return this;
84
};
85
86
/**
87
 * Get the date
88
 * 
89
 * @returns {Date} date
90
 */
91
Name.prototype.getDate = function(){
92
  return this.date;
93
};
94
95
/**
96
 * Set the date
97
 * 
98
 * @param {Date|Object} date
99
 * @returns {Fact} This instance
100
 */
101
Name.prototype.setDate = function(date){
102
  if(date){
103
    this.date = GedcomX.Date(date);
104
  }
105
  return this;
106
};
107
108
/**
109
 * Get the name forms
110
 * 
111
 * @return {NameForm[]}
112
 */
113
Name.prototype.getNameForms = function(){
114
  return this.nameForms || [];
115
};
116
117
/**
118
 * Set the name forms
119
 * 
120
 * @param {NameForm[]|Object[]} nameForms
121
 * @returns {Name} This instance
122
 */
123
Name.prototype.setNameForms = function(nameForms){
124
  return this._setArray(nameForms, 'nameForms', 'addNameForm');
125
};
126
127
/**
128
 * Add a name form
129
 * 
130
 * @param {NameForm|Object} nameForm
131
 * @returns {Name} This instance
132
 */
133
Name.prototype.addNameForm = function(nameForm){
134
  return this._arrayPush(nameForm, 'nameForms', GedcomX.NameForm);
135
};
136
137
/**
138
 * Export the object as JSON
139
 * 
140
 * @return {Object} JSON object
141
 */
142
Name.prototype.toJSON = function(){
143
  return this._toJSON(GedcomX.Conclusion, Name.jsonProps);
144
};
145
146
module.exports = Name;